package top.zuli.package01.class14;

public class WindowTest4 {
    public static void main(String[] args) {
        Thread t1 = new Window4();
        Thread t2 = new Window4();
        Thread t3 = new Window4();
        t1.start();
        t2.start();
        t3.start();
    }
}

class Window4 extends Thread{
    private static int ticket = 100;
    private static boolean tag = true;
    @Override
    public void run() {
        while (tag){
            show();
        }
    }
    public static synchronized void show(){//相当于Window4.class,方法用的锁就是方法的所属者
        if(ticket>0){
            try {
                sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"卖票,票号："+ticket);
            ticket--;
        } else {
            tag = false;
        }
    }
}
